function ajaxFun(){
    var ajaxData = {
        type:arguments[0].type || "GET",
        url:arguments[0].url || "",
        async:arguments[0].async || "true",
        data:arguments[0].data || null,
        dataType:arguments[0].dataType || "text",
        contentType:arguments[0].contentType || "application/x-www-form-urlencoded",
        beforeSend:arguments[0].beforeSend || function(){},
        success:arguments[0].success || function(){},
        error:arguments[0].error || function(){}
    }
    ajaxData.beforeSend()
    var xhr = createxmlHttpRequest();
    xhr.responseType=ajaxData.dataType;
    xhr.open(ajaxData.type,ajaxData.url,ajaxData.async);
    xhr.setRequestHeader("Content-Type",ajaxData.contentType);
    xhr.send(convertData(ajaxData.data));
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            if(xhr.status == 200){
                ajaxData.success(xhr.response)
            }else{
                ajaxData.error()
            }
        }
    }
}
function createxmlHttpRequest() {
    if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
}

function convertData(data){
    if( typeof data === 'object' ){
        var convertResult = "" ;
        for(var c in data){
            convertResult+= c + "=" + data[c] + "&";
        }
        convertResult=convertResult.substring(0,convertResult.length-1);
        return convertResult;
    }else{
        return data;
    }
}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]);
    return null;
}
function wechatLogin(url) {
    ajaxFun({
        url: '/system/system/getWechatPublic',
        type: 'get',
        cache: false,  //禁用缓存
        dataType: 'json',
        success: function (data) {
            if (data.code==200){
                var appid = data.data.wechat_public_app_id;
                var domain = data.data.wechat_public_app_domain||window.location.origin;
                window.sessionStorage.setItem('toUrl',url);
                if (data.data.wechat_public_app_domain){
                    window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid='+appid+'&redirect_uri='+encodeURI(domain+'/public/transit/getWechatPublicCode.html?nowdomain='+window.location.origin+'&v='+new Date().getTime())+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
                } else{
                    window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid='+appid+'&redirect_uri='+domain+'/public/transit/getWechatCode.html?v='+(new Date().getTime())+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
                }
            }else{
                alert(data.msg)
            }
        },
        error:function(){
            // layer.msg("网络错误，请稍后重试")
        }
    });
}